home *** CD-ROM | disk | FTP | other *** search
/ Electronic Clipper 1995 April / Electronic Clipper 1995-04.iso / pc / pc_users / ideasrc / setup / mplayer / framewnd.c < prev    next >
Text File  |  1993-04-17  |  43KB  |  1,063 lines

  1.  
  2. // ---------------------------------------------------------------------
  3. //
  4. // FrameWnd.c - Movie Player - QuickTime for Windows
  5. //
  6. //              Version 1.0
  7. //
  8. //              (c) 1988-1992 Apple Computer, Inc. All Rights Reserved.
  9. //
  10. // ---------------------------------------------------------------------
  11.  
  12.  
  13. // Includes
  14. // --------
  15.    #include <Windows.H>                // Required by Windows
  16.    #include <commdlg.h>                // Header file for common dlgs
  17.    #include <dlgs.h>                   // Header file for common dlgs ids
  18.    #include <cderr.h>                  // Header file for error ids
  19.    #include <memory.h>                 // For memset()
  20.    #include <shellapi.h>               // Required for drag and drop
  21.  
  22.    #include <qtole.h>                  // Interface to qtole dll's
  23.  
  24.    #include "common.h"                 // Interface to common.c
  25.  
  26.    #include "player.h"                 // Interface to other *.c files
  27.    #include "player.hr"                // Defines used in *.rc files
  28.  
  29.  
  30. // Message-Persistent Data
  31. // -----------------------
  32.    static struct                       // Hungarian notation: g
  33.      { HWND      hwndClient;           // MDI client window
  34.        WORD      wNumMovies;           // Number of movie wnds
  35.        BOOL      bUserAbortPrint;      // User abort print flag
  36.        HWND      hwndCancelPrt;        // Handle of print cancel dlg
  37.        HBITMAP   hAboutBitmap;         // Temp static storage of bitmap
  38.                                        // displayed in about dialogs
  39.        WORD      wTileCascadeArrange;  // Indicates tiling, cascading or
  40.                                        // icon arrange
  41.        BOOL      bIconized;            // TRUE while frame wnd is iconized
  42.        BOOL      bRestoring;           // TRUE if restoring iconized frame wnd
  43.      } g;
  44.  
  45.  
  46. // Exported callback functions
  47. // ----------------------------
  48.    BOOL __export CALLBACK AboutDlgProc       (HWND, UINT, WPARAM, LPARAM);
  49.    BOOL __export CALLBACK CloseEnumProc      (HWND, LPARAM);
  50.    BOOL __export CALLBACK MovieEnumProc      (HWND, LPARAM);
  51.    BOOL __export CALLBACK PrintCancelDlgProc (HWND, UINT, WPARAM, LPARAM);
  52.    int  __export CALLBACK PrintAbortProc     (HDC, int);
  53.    UINT __export CALLBACK PrintDlgHookProc   (HWND, UINT, WPARAM, LPARAM);
  54.  
  55. // Internal Function Declarations
  56. // ------------------------------
  57.    static LONG NEAR PlayerFrameCreate       (HWND);
  58.    static LONG NEAR PlayerFileCommands      (HWND, WPARAM, WORD);
  59.    static LONG NEAR PlayerWindowCommands    (HWND, WPARAM, WORD);
  60.    static LONG NEAR PlayerHelpCommands      (HWND, WPARAM, WORD);
  61.    static LONG NEAR LaunchMovieWnd          (LPSTR, LPSTR);
  62.    static VOID NEAR PlayerEnableMenus       (HWND, BOOL);
  63.    static VOID NEAR TellUserCommonDlgError  (DWORD);
  64.    static LONG NEAR ProcessDroppedFiles     (HWND, WPARAM);
  65.    static VOID NEAR DestroyHelpInstance     (HWND);
  66.    
  67. // -----------------------------------------------------------------------
  68.  
  69.  
  70. // Function: PlayerFrameWndProc - Player Frame Window Procedure
  71. // --------------------------------------------------------------------
  72. // Parameters: As required by Microsoft Windows
  73. //
  74. // Returns:    Via DefFrameProc
  75. // --------------------------------------------------------------------
  76.    LONG __export CALLBACK PlayerFrameWndProc
  77.               (HWND hwndFrame, UINT message, WPARAM wParam, LPARAM lParam)
  78.  
  79.      {WNDENUMPROC       lpfnEnumMovies;    // -> callback funcion for
  80.                                            // enumeration of movies
  81.       HWND              hwndMovie;         // Temp handle of active movie wnd
  82.       LPQTOLE_OLEDATA   lpOleData;         // -> ole data
  83.  
  84.       switch( message )
  85.         {case WM_CREATE:
  86.             return PlayerFrameCreate( hwndFrame );
  87.  
  88.          case WM_PALETTECHANGED:
  89.             if( g.wNumMovies &&
  90.                     ( lpfnEnumMovies = (WNDENUMPROC) MakeProcInstance
  91.                        ( (FARPROC) MovieEnumProc, PlayerQueryInstance())))
  92.                {   // Tell the movie wnds to repaint
  93.                 EnumChildWindows( g.hwndClient, lpfnEnumMovies,
  94.                                                        (LPARAM) message);
  95.                 FreeProcInstance( (FARPROC) lpfnEnumMovies );
  96.                }
  97.  
  98.             return 0L;
  99.             
  100.          case WM_SIZE:
  101.             if( wParam == SIZE_MINIMIZED )
  102.                {g.bIconized  = TRUE;
  103.                 g.bRestoring = FALSE;
  104.                }
  105.             else if( g.bIconized && 
  106.                    (( wParam == SIZE_RESTORED ) ||
  107.                                   ( wParam == SIZE_MAXIMIZED )))
  108.                {g.bIconized  = FALSE;
  109.                 g.bRestoring = TRUE;
  110.                }
  111.  
  112.             if( g.wNumMovies &&
  113.                     ( lpfnEnumMovies = (WNDENUMPROC) MakeProcInstance
  114.                        ( (FARPROC) MovieEnumProc, PlayerQueryInstance())))
  115.                {   // Tell the movie wnds to reset their grow box bounds rect
  116.                 EnumChildWindows( g.hwndClient, lpfnEnumMovies, 
  117.                                                        (LPARAM) message);
  118.                 FreeProcInstance( (FARPROC) lpfnEnumMovies );
  119.                }
  120.  
  121.             if( g.bRestoring )
  122.                {g.bRestoring = FALSE;
  123.                }
  124.  
  125.             break;    // break to DefFrameProc
  126.  
  127.  
  128.          case WM_INITMENUPOPUP:
  129.    // Set check marks and enable menu items in popups
  130.             if( !(BOOL) HIWORD( lParam ) &&
  131.                      ( hwndMovie = (HWND) SendMessage
  132.                             ( g.hwndClient, WM_MDIGETACTIVE, 0, 0l )) &&
  133.                                                        IsWindow( hwndMovie ))
  134.                 SendMessage( hwndMovie, WM_PLAYER_INITPOPUPS, wParam, lParam );
  135.  
  136.             return 0L;
  137.  
  138.          case WM_COMMAND:
  139.             switch( wParam )
  140.                {case PLAYER_FILE_OPEN:        // file menu popup
  141.                 case PLAYER_FILE_CLOSE:
  142.                 case PLAYER_FILE_PRTSETUP:
  143.                 case PLAYER_FILE_PRINT:
  144.                 case PLAYER_FILE_EXIT:
  145.                     return PlayerFileCommands
  146.                                     ( hwndFrame, wParam, HIWORD (lParam));
  147.  
  148.                 case PLAYER_WINDOW_TILE:     // window menu popup
  149.                 case PLAYER_WINDOW_CASCADE:
  150.                 case PLAYER_WINDOW_ARRANGE:
  151.                     return PlayerWindowCommands
  152.                                     ( hwndFrame, wParam, HIWORD (lParam));
  153.  
  154.  
  155.                 case PLAYER_HELP_PLAYERHELP: // help menu popup
  156.                 case PLAYER_HELP_USINGHELP:
  157.                 case PLAYER_HELP_ABOUTPLAYER:
  158.                     return PlayerHelpCommands
  159.                                     ( hwndFrame, wParam, HIWORD( lParam ));
  160.  
  161.                 default:
  162.                     if( ( hwndMovie = (HWND) SendMessage
  163.                              ( g.hwndClient, WM_MDIGETACTIVE, 0, 0L )) &&
  164.                                                        IsWindow( hwndMovie ))
  165.                        SendMessage( hwndMovie, WM_COMMAND, wParam, lParam );
  166.  
  167.                     break;    // break to DefFrameProc
  168.                } 
  169.  
  170.             break;
  171.  
  172.     // WM_USER messages
  173.  
  174.          case WM_PLAYER_CMDLINE:
  175.             return LaunchMovieWnd( (LPSTR) lParam, NULL );
  176.  
  177.          case WM_PLAYER_MOVIEDELETED:
  178.     // Decrement movie count. This is incremented in LaunchMovieWnd
  179.     // when movie is created
  180.             if( --g.wNumMovies <= 0 )
  181.                 PlayerEnableMenus( hwndFrame, FALSE );
  182.             return 0L;
  183.  
  184.     // These next messages are posted by the ole callback function in MovieUtl.c
  185.          case WM_PLAYER_OLE_OPTIONSDLG:
  186.             PlayerGetOptions( NULL, (LPQTOLE_OPTIONSMOVIE) lParam );
  187.             return 0L;
  188.  
  189.          case WM_PLAYER_OLE_PLAYOBJECT:
  190.             QTOLE_PlayObject( PlayerQueryOleData(), lParam );
  191.             return 0L;
  192.  
  193.     // end WM_USER messages
  194.  
  195.  
  196.     // Standard drag and drop processing. Allows for multiple movies but
  197.     // does not worry about position of drop
  198.          case WM_DROPFILES:
  199.             return ProcessDroppedFiles( hwndFrame, wParam );
  200.  
  201.          case WM_QUERYENDSESSION:
  202.          case WM_CLOSE:
  203.             if( g.wNumMovies &&
  204.                   ( lpfnEnumMovies = (WNDENUMPROC) MakeProcInstance
  205.                         ( (FARPROC) CloseEnumProc, PlayerQueryInstance())))
  206.                 {  // Give all movies a chance to stop the close
  207.                  EnumChildWindows( g.hwndClient, lpfnEnumMovies, 0L );
  208.                  FreeProcInstance( (FARPROC) lpfnEnumMovies );
  209.  
  210.                    // If someone didn't want to close, don't kill the app
  211.                  if( NULL != GetWindow( g.hwndClient, GW_CHILD ))
  212.                      return 0L;
  213.                 }
  214.  
  215.                // Tell qtole.dll that we are closing the server
  216.                // Don't close if QTOLE_ClossingServerWnd returns FALSE;
  217.             if( ( lpOleData = PlayerQueryOleData()) && 
  218.                          lpOleData->lpqtoleServer &&
  219.                                 !QTOLE_ClosingServerWnd( lpOleData, message ))
  220.                 return 0L;
  221.  
  222.             break;  // break to DefFrameProc
  223.  
  224.          case WM_DESTROY:
  225.             DragAcceptFiles( hwndFrame, FALSE );
  226.  
  227.                // Destroy help instance
  228.             DestroyHelpInstance( hwndFrame );
  229.  
  230.                // NULL the hwnd globals in playmain.c
  231.             PlayerNoMoreWindow();
  232.  
  233.             PostQuitMessage( 0 );
  234.             break;
  235.  
  236.         }
  237.  
  238.       return DefFrameProc
  239.                      ( hwndFrame, g.hwndClient, message, wParam, lParam );
  240.      }
  241.  
  242.  
  243. // Function: PlayerFrameCreate - process WM_CREATE message
  244. // --------------------------------------------------------------------
  245. // Parameters: HWND hwndFrame;         Frame window
  246. //
  247. // Returns:    0L if OK, else returns -1L to kill app
  248. // --------------------------------------------------------------------
  249.    static LONG NEAR PlayerFrameCreate( HWND hwndFrame )
  250.  
  251.      {CLIENTCREATESTRUCT  clientcreate;    // MDI client create struct
  252.       char                szCaption[50];   // caption buffer;
  253.  
  254.  
  255.       szCaption[0] = '\0';
  256.       if( LoadString( PlayerQueryResources(), PLAYER_STRING_CAPTION,
  257.                                           szCaption, sizeof( szCaption )))
  258.           SetWindowText( hwndFrame, szCaption );
  259.    // No point in trying for an error message here since it probably won't
  260.    // load either.
  261.  
  262.    // disable menu items until a movie is created
  263.       g.wNumMovies = 0;
  264.       PlayerEnableMenus( hwndFrame, FALSE );
  265.  
  266.       DragAcceptFiles( hwndFrame, TRUE );
  267.  
  268.       clientcreate.hWindowMenu =
  269.                       GetSubMenu( GetMenu( hwndFrame ), MENU_WINDOW_POS );
  270.       clientcreate.idFirstChild = PLAYER_CLIENT_FIRSTCHILD;
  271.  
  272.       if( !(g.hwndClient = CreateWindow("MDICLIENT", NULL,
  273.                    WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE |
  274.                                   WS_HSCROLL | WS_VSCROLL,
  275.                    0, 0, 0, 0, hwndFrame, ( HMENU) 1,
  276.                    PlayerQueryInstance(), (LPVOID) &clientcreate )))
  277.           return -1L;                 // return -1 to kill app
  278.       else
  279.           return  0L;
  280.      }
  281.  
  282.  
  283. // Function: PlayerFileCommands - Process WM_COMMAND, File popup messages
  284. // --------------------------------------------------------------------
  285. // Parameters: HWND   hwndFrame;      Frame window
  286. //             WORD   wIDItem;        Menu or control id
  287. //             WORD   wNotifyCode;    notification message
  288. //
  289. // Returns:    LONG   generally 0L
  290. // --------------------------------------------------------------------
  291.    static LONG NEAR PlayerFileCommands
  292.                        (HWND hwndFrame, WPARAM wIDItem, WORD wNotifyCode )
  293.  
  294.      {HWND           hwndMovie;                  // Handle of movie window
  295.       OPENFILENAME   ofn;                        // OPENFILENAME struct
  296.       UINT           cbString;                   // Length of filter string
  297.       char           szMoviePath[256];           // Movie file path
  298.                                                  // Must be at least 256 bytes
  299.       char           szMovieName[MAX_NAME_LEN];  // Movie file name
  300.       char           szFilter[256];              // Movie file filter str
  301.       LPSTR          lpTemp;                     // Temp -> to string
  302.       LPSTR          lpSave;                     // Temp -> to string
  303.       char           chReplace;                  // String separator used in filter string
  304.       DWORD          dwError;                    // Common dlg error return
  305.       PRINTDLG       pd;                         // Print common dlg struct
  306.       ABORTPROC      lpPrintAbortProc;           // Print abort proc
  307.       DLGPROC        lpPrtCancelProc;            // Print cancel dlg proc
  308.       WORD           wIDError;                   // Resource errror string id
  309.       int            nError;                     // Error return;
  310.  
  311.  
  312.    typedef UINT ( CALLBACK * PRINTDLGHOOKPROC ) ( HWND, UINT, WPARAM, LPARAM );
  313.  
  314.  
  315.       switch( wIDItem )
  316.         {case PLAYER_FILE_OPEN:
  317.             memset( &ofn, 0, sizeof( OPENFILENAME ));
  318.             szMoviePath[0] = '\0';
  319.  
  320.             if( !(cbString = LoadString( PlayerQueryResources(),
  321.                                   PLAYER_STRING_OPENMOVIEFILTER,
  322.                                           szFilter, sizeof( szFilter ))))
  323.                 return 0L;
  324.  
  325.    // See 3.1 SDK manuals, vol. 1 for examples of common dlg processing
  326.             lpTemp = szFilter + lstrlen( szFilter );
  327.             chReplace = *AnsiPrev( szFilter, lpTemp );
  328.             lpTemp = szFilter;
  329.             while( *lpTemp )
  330.                 {if( *lpTemp == chReplace )
  331.                     {  // Need to increment pointer past chReplace before
  332.                        // setting to NULL. Otherwise AnsiNext thinks it is
  333.                        // at end of string and quits
  334.                      lpSave = lpTemp;
  335.                      lpTemp = AnsiNext( lpTemp );
  336.                      *lpSave = '\0';
  337.                     }
  338.                  else
  339.                      lpTemp = AnsiNext( lpTemp );
  340.                 }
  341.  
  342.             ofn.lStructSize    = sizeof( OPENFILENAME );
  343.             ofn.hwndOwner      = hwndFrame;
  344.             ofn.lpstrFilter    = szFilter;
  345.             ofn.nFilterIndex   = 1;
  346.             ofn.lpstrFile      = szMoviePath;
  347.             ofn.nMaxFile       = sizeof( szMoviePath );
  348.             ofn.lpstrFileTitle = szMovieName;
  349.             ofn.nMaxFileTitle  = sizeof( szMovieName );
  350.             ofn.Flags          = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST |
  351.                                                           OFN_HIDEREADONLY;
  352.  
  353.             if( GetOpenFileName( &ofn ))
  354.                 LaunchMovieWnd( szMoviePath, szMovieName );
  355.             else if( dwError = CommDlgExtendedError() )
  356.                {  // Tell the user about the error
  357.                 TellUserCommonDlgError( dwError );
  358.                }
  359.  
  360.             return 0L;
  361.  
  362.          case PLAYER_FILE_CLOSE:
  363.             if( ( hwndMovie = (HWND) SendMessage
  364.                         ( g.hwndClient, WM_MDIGETACTIVE, 0, 0L )) &&
  365.                                                 IsWindow( hwndMovie ))
  366.                 SendMessage( hwndMovie, WM_CLOSE, 0, 0L );
  367.  
  368.             return 0L;
  369.  
  370.          case PLAYER_FILE_PRTSETUP:
  371.             memset( &pd, 0, sizeof( PRINTDLG ));
  372.  
  373.             pd.lStructSize = sizeof( PRINTDLG );
  374.             pd.hwndOwner   = hwndFrame;
  375.             pd.Flags       = PD_PRINTSETUP;
  376.  
  377.             if( ( PrintDlg( &pd ) == 0 ) &&
  378.                                      ( dwError = CommDlgExtendedError() ))
  379.                {  // Tell the user about the error
  380.                 TellUserCommonDlgError( dwError );
  381.                }
  382.  
  383.             return 0L;
  384.  
  385.          case PLAYER_FILE_PRINT:
  386.             memset( &pd, 0, sizeof( PRINTDLG ));
  387.  
  388.             pd.lStructSize = sizeof( PRINTDLG );
  389.             pd.hwndOwner   = hwndFrame;
  390.             pd.Flags       = PD_RETURNDC |
  391.                                  PD_ENABLEPRINTHOOK | PD_ENABLEPRINTTEMPLATE;
  392.             pd.hInstance   = PlayerQueryResources();
  393.             pd.lpPrintTemplateName = MAKEINTRESOURCE( CUSTOM_DLG_COMN_PRINT );
  394.             if( !( pd.lpfnPrintHook =  (PRINTDLGHOOKPROC) 
  395.                       MakeProcInstance( (FARPROC) PrintDlgHookProc,
  396.                                                      PlayerQueryInstance())))
  397.                {CommonTellUser( PlayerQueryResources(), 
  398.                                       PLAYER_STRING_NOMEMORY, NULL, MB_OK );
  399.                 return 0L;
  400.                }
  401.  
  402.             if( PrintDlg( &pd ) != 0 )
  403.                {lpPrtCancelProc = (DLGPROC) MakeProcInstance
  404.                     ( (FARPROC) PrintCancelDlgProc, PlayerQueryInstance() );
  405.  
  406.                 lpPrintAbortProc = (ABORTPROC) MakeProcInstance
  407.                        ( (FARPROC) PrintAbortProc, PlayerQueryInstance() );
  408.  
  409.                 if( !lpPrtCancelProc || !lpPrintAbortProc )
  410.                    {CommonTellUser( PlayerQueryResources(),
  411.                              PLAYER_STRING_NOMEMORY, NULL, MB_OK );
  412.                     return 0L;
  413.                    }
  414.  
  415.                 g.bUserAbortPrint = FALSE;
  416.                 nError   = 0;
  417.                 wIDError = 0;
  418.  
  419.                 if( !(g.hwndCancelPrt =
  420.                           CreateDialog( PlayerQueryResources(),
  421.                                  MAKEINTRESOURCE( PLAYER_DLG_PRINTCANCEL ),
  422.                                           hwndFrame, lpPrtCancelProc )))
  423.                    {wIDError = PLAYER_STRING_CANCELDLG;
  424.                    }
  425.                 else
  426.                    {EnableWindow( hwndFrame, FALSE );   // disable frame window
  427.                     if( SetAbortProc( pd.hDC, lpPrintAbortProc ) <= 0 )
  428.                         wIDError = PLAYER_STRING_ABORTPROC;
  429.                     else
  430.                        {if( hwndMovie = (HWND) SendMessage
  431.                               ( g.hwndClient, WM_MDIGETACTIVE, 0, 0L ))
  432.                             nError = (int) SendMessage( hwndMovie,
  433.                                         WM_PLAYER_PRINTFRAME, 0,
  434.                                            (LPARAM) (LPPRINTDLG) &pd );
  435.                         if( ( nError < 0 ) &&
  436.                                   ( nError & SP_NOTREPORTED ) &&
  437.                                                    !g.bUserAbortPrint )
  438.                            {switch( nError )
  439.                                {case SP_APPABORT:
  440.                                 case SP_USERABORT:
  441.                                     break;
  442.                                 case SP_OUTOFDISK:
  443.                                     wIDError = PLAYER_STRING_PRT_OUTOFDISK;
  444.                                     break;
  445.                                 case SP_OUTOFMEMORY:
  446.                                     wIDError = PLAYER_STRING_PRT_NOMEMORY;
  447.                                     break;
  448.                                 case SP_ERROR:   // fall through
  449.                                 default:
  450.                                     wIDError = PLAYER_STRING_PRT_GENERROR;
  451.                                     break;
  452.                                }
  453.                            }
  454.                        }
  455.  
  456.                     EnableWindow( hwndFrame, TRUE );   // reenable frame window
  457.  
  458.                     if( g.hwndCancelPrt )
  459.                         DestroyWindow( g.hwndCancelPrt );
  460.                    }
  461.  
  462.                 if( wIDError )
  463.                     CommonTellUser( PlayerQueryResources(), wIDError,
  464.                                       PLAYER_STRING_PRT_CAPTION, MB_OK );
  465.  
  466.                 FreeProcInstance( (FARPROC) lpPrtCancelProc );
  467.                 FreeProcInstance( (FARPROC) lpPrintAbortProc );
  468.  
  469.                 if( pd.hDC != NULL )
  470.                     DeleteDC( pd.hDC );
  471.                 if( pd.hDevMode != NULL )
  472.                     GlobalFree( pd.hDevMode );
  473.                 if( pd.hDevNames != NULL )
  474.                     GlobalFree( pd.hDevNames );
  475.  
  476.                }
  477.             else if( dwError = CommDlgExtendedError() )
  478.                {  // Tell the user about the error
  479.                 TellUserCommonDlgError( dwError );
  480.                }
  481.  
  482.             return 0L;
  483.  
  484.          case PLAYER_FILE_EXIT:
  485.             SendMessage( hwndFrame, WM_CLOSE, 0, 0L );
  486.             return 0L;
  487.         }
  488.  
  489.       return 0L;      // should never get here
  490.  
  491.      }
  492.  
  493.  
  494. // Function: PlayerWindowCommands - Process WM_COMMAND, Window popup messages
  495. // --------------------------------------------------------------------
  496. // Parameters: HWND   hwndFrame;      Frame window
  497. //             WORD   wIDItem;        Menu or control id
  498. //             WORD   wNotifyCode;    notification message
  499. //
  500. // Returns:    LONG   generally 0L
  501. // --------------------------------------------------------------------
  502.    static LONG NEAR PlayerWindowCommands
  503.                        (HWND hwndFrame, WPARAM wIDItem, WORD wNotifyCode )
  504.  
  505.    // Tile and cascade are implemented using modifications of
  506.    // the standard MDI processing in order to preserve the size
  507.    // and aspect ratio of the movies. The modifications are implemented
  508.    // in MovieWnd.c on the basis of the value of g.wTileCascadeArrange
  509.  
  510.      {
  511.       g.wTileCascadeArrange = wIDItem;
  512.  
  513.       switch( wIDItem )
  514.         { // Modify the tile using the WM_WINDOWPOSCHANGING message in 
  515.           // the movie window processing to set the original aspect
  516.           // ratio and, if possible, size of the movies
  517.          case PLAYER_WINDOW_TILE:
  518.             SendMessage( g.hwndClient, WM_MDITILE, 0, 0L );
  519.             break;
  520.  
  521.           // Modify the cascade using the WM_GETMINMAXINFO message in 
  522.           // the movie window processing to preserve the current size
  523.           // of the movies
  524.          case PLAYER_WINDOW_CASCADE:
  525.             SendMessage( g.hwndClient, WM_MDICASCADE, 0, 0L );
  526.             break;
  527.         
  528.            // This is standard MDI. 
  529.          case PLAYER_WINDOW_ARRANGE:
  530.             SendMessage( g.hwndClient, WM_MDIICONARRANGE, 0, 0L );
  531.             break;
  532.         }
  533.  
  534.       g.wTileCascadeArrange = 0;
  535.  
  536.       return 0L; 
  537.  
  538.      }
  539.  
  540.  
  541. // Function: PlayerHelpCommands - Process WM_COMMAND, Help popup messages
  542. // --------------------------------------------------------------------
  543. // Parameters: HWND   hwndFrame;      Frame window
  544. //             WORD   wIDItem;        Menu or control id
  545. //             WORD   wNotifyCode;    notification message
  546. //
  547. // Returns:    LONG   generally 0L
  548. // --------------------------------------------------------------------
  549.    static LONG NEAR PlayerHelpCommands
  550.                        (HWND hwndFrame, WPARAM wIDItem, WORD wNotifyCode )
  551.  
  552.      {char       szHelp[MAX_PATH_LEN];     // Help file path
  553.       DLGPROC    lpDlgProc;                // -> dialog proc
  554.  
  555.       switch( wIDItem )
  556.         {case PLAYER_HELP_PLAYERHELP:
  557.             CommonGetLocalizedHelpFile
  558.                       ( PLAYER_ROOT_NAME, szHelp, PlayerQueryInstance() );
  559.  
  560.             if( szHelp[0] )
  561.                 WinHelp( hwndFrame, (LPCSTR) szHelp, HELP_CONTENTS, 0L );
  562.             else
  563.                 CommonTellUser( PlayerQueryResources(),
  564.                                      PLAYER_STRING_NOHELPFILE,
  565.                                           PLAYER_STRING_CAPTION, MB_OK );
  566.  
  567.             return 0L;
  568.  
  569.          case PLAYER_HELP_USINGHELP:
  570.             WinHelp( hwndFrame, "WINHELP.HLP", HELP_CONTENTS, 0L );
  571.             return 0L;
  572.  
  573.          case PLAYER_HELP_ABOUTPLAYER:
  574.             if( ( g.hAboutBitmap = LoadBitmap( PlayerQueryResources(),
  575.                           MAKEINTRESOURCE( PLAYER_PLAYER_BITMAP ))) &&
  576.                     ( lpDlgProc = (DLGPROC) MakeProcInstance
  577.                        ( (FARPROC) AboutDlgProc, PlayerQueryInstance())))
  578.                {DialogBox( PlayerQueryResources(),
  579.                              MAKEINTRESOURCE( PLAYER_DLG_ABOUTPLAYER ),
  580.                                                 hwndFrame, lpDlgProc );
  581.                 FreeProcInstance( (FARPROC) lpDlgProc );
  582.                }
  583.             else
  584.                 CommonTellUser( PlayerQueryResources(),
  585.                                  PLAYER_STRING_NOMEMORY,
  586.                                         PLAYER_STRING_CAPTION, MB_OK );
  587.             if( g.hAboutBitmap )
  588.                 DeleteObject( g.hAboutBitmap );
  589.             g.hAboutBitmap = NULL;
  590.  
  591.             return 0L;
  592.         }
  593.  
  594.       return 0L;      // should never get here
  595.  
  596.      }
  597.  
  598. //// the following are some utility routines
  599.  
  600. // Function: CloseEnumProc - Close all enumerate proc
  601. // --------------------------------------------------------------------
  602. // Parameters: As required by Microsoft Windows
  603. //
  604. // Returns:    Always TRUE to enumerate all windows
  605. // --------------------------------------------------------------------
  606.    BOOL __export CALLBACK CloseEnumProc( HWND hwnd, LPARAM lParam )
  607.  
  608.      {char   szClassName[40];      // Temp buffer for class name
  609.  
  610.    // Check class name since there are several classes of child windows
  611.       if( !GetClassName( hwnd, szClassName, sizeof( szClassName )) ||
  612.                            lstrcmpi( szClassName, PLAYER_MOVIE_CLASS ))
  613.           return TRUE;
  614.  
  615.           // If  someone doesn't want to close, stop enumeration
  616.       if( !SendMessage( hwnd, WM_QUERYENDSESSION, 0, 0L ))
  617.           return FALSE;
  618.  
  619.       SendMessage( GetParent( hwnd ), WM_MDIDESTROY, (WPARAM) hwnd, 0L );
  620.  
  621.       return TRUE;
  622.      }
  623.  
  624. // Function: MovieEnumProc - Tells all movie wnds to do something
  625. // --------------------------------------------------------------------
  626. // Parameters: As required by Microsoft Windows
  627. //
  628. // Returns:    Always TRUE to enumerate all windows
  629. // --------------------------------------------------------------------
  630.    BOOL __export CALLBACK MovieEnumProc( HWND hwnd, LPARAM lParam )
  631.  
  632.      {char    szClassName[40];      // Temp buffer for class name
  633.  
  634.    // Check class name since there are several classes of child windows
  635.       if( !GetClassName( hwnd, szClassName, sizeof( szClassName )) ||
  636.                            lstrcmpi( szClassName, PLAYER_MOVIE_CLASS ))
  637.           return TRUE;
  638.  
  639.       if( LOWORD( lParam ) == WM_PALETTECHANGED )
  640.             // Tell the movies to repaint. The background is fixed up in the
  641.             // paint processing
  642.           InvalidateRect( hwnd, NULL, FALSE );
  643.       else if( LOWORD( lParam ) == WM_SIZE )
  644.          {SendMessage( hwnd, WM_PLAYER_UPDATEGBBOUNDSRECT, 0, 0L );
  645.               // Tell movies to stop if we are iconizing and to restart
  646.               // if restoring
  647.           if( g.bIconized || g.bRestoring )
  648.               SendMessage( hwnd, WM_PLAYER_PLAYTHEMOVIE,
  649.                                         (WPARAM ) g.bRestoring, 0L );
  650.          }
  651.  
  652.       return TRUE;
  653.      }
  654.  
  655.  
  656. // Function: LaunchMovieWnd - tell hwndClient to launch a movie wnd
  657. // --------------------------------------------------------------------
  658. // Parameters: LPSTR     lpMoviePath      Path of movie file
  659. //             LPSTR     lpName           File name of movie file
  660. //
  661. // Returns:    LONG    0L if OK, else nonzero
  662. // --------------------------------------------------------------------
  663.    static LONG NEAR LaunchMovieWnd( LPSTR lpMoviePath, LPSTR lpName )
  664.  
  665.      {MDICREATESTRUCT    mdicreate;        // mdi create struct
  666.       HWND               hwndMovie;        // Temp handle of window
  667.  
  668.       if( !lpMoviePath[0] )
  669.           return -1L;
  670.  
  671.       if( lpName == NULL )
  672.           {lpName = lpMoviePath + lstrlen( lpMoviePath );
  673.            lpName = AnsiPrev( lpMoviePath, lpName );
  674.            while( *lpName && (*lpName != '\\') && (lpName != lpMoviePath))
  675.               lpName = AnsiPrev( lpMoviePath, lpName );
  676.            if( *lpName == '\\' )
  677.               lpName = AnsiNext( lpName );
  678.           }
  679.  
  680.       mdicreate.szClass = PLAYER_MOVIE_CLASS;
  681.       mdicreate.szTitle = AnsiLower( lpName );
  682.       mdicreate.hOwner  = PlayerQueryInstance();
  683.       mdicreate.x       = CW_USEDEFAULT;
  684.       mdicreate.y       = CW_USEDEFAULT;
  685.       mdicreate.cx      = CW_USEDEFAULT;
  686.       mdicreate.cy      = CW_USEDEFAULT;
  687.       mdicreate.style   = 0;
  688.       mdicreate.lParam  = (LPARAM) lpMoviePath;
  689.  
  690.       if( !( hwndMovie = (HWND) SendMessage
  691.                  ( g.hwndClient, WM_MDICREATE, 0,
  692.                               (LPARAM) (LPMDICREATESTRUCT) &mdicreate )))
  693.          {return -1L;
  694.          }
  695.       else
  696.          {if(++g.wNumMovies == 1 )
  697.              PlayerEnableMenus( PlayerQueryFrameWindow(), TRUE );
  698.           return 0L;
  699.          }
  700.      }
  701.  
  702. // Function: ProcessDroppedFiles - Process the WM_DROPFILES message
  703. // --------------------------------------------------------------------
  704. // Parameters: HWND     hwndFrame         Frame window handle
  705. //             WPARAM   wParam            Message wParam
  706. //
  707. // Returns:    LONG     Always 0L;
  708. // --------------------------------------------------------------------
  709.    static LONG NEAR ProcessDroppedFiles( HWND hwndFrame, WPARAM wParam )
  710.  
  711.      {int           i;                         // Temp counter
  712.       int           nNumFiles;                 // Temp number of dropped files
  713.       UINT          uBytes;                    // Temp len of drop file path
  714.       char          szDropFile[MAX_PATH_LEN];  // Temp drop file path
  715.       
  716.       if( nNumFiles = DragQueryFile( (HDROP) wParam, 0xffff,
  717.                                                       (LPSTR) NULL, 0 ))
  718.          {  // Create processing requires that frame window has
  719.             // nonzero dimensions so first restore iconized wnd
  720.           if( IsIconic( hwndFrame ))
  721.               ShowWindow( hwndFrame, SW_SHOWNORMAL );
  722.  
  723.           for( i=0; i < nNumFiles; i++ )
  724.              {uBytes = DragQueryFile( (HDROP) wParam, i,
  725.                               (LPSTR) szDropFile, sizeof( szDropFile ));
  726.               if( uBytes > 0 )
  727.                   LaunchMovieWnd( szDropFile, NULL );
  728.              }
  729.          }
  730.  
  731.       DragFinish( (HDROP) wParam );
  732.  
  733.       return 0L;
  734.      }
  735.  
  736.  
  737. // Function: DestroyHelpInstance - Tell windows that instance is done with
  738. //                                 help. This is called as a function so that
  739. //                                 szHelp[] is not an automatic var. in the
  740. //                                 winproc
  741. // --------------------------------------------------------------------
  742. // Parameters: HWND     hwndFrame         Frame window handle
  743. //
  744. // Returns:    VOID
  745. // --------------------------------------------------------------------
  746.    static VOID NEAR DestroyHelpInstance( HWND hwndFrame )
  747.  
  748.      {char    szHelp[MAX_PATH_LEN];           // Help file name
  749.  
  750.       WinHelp( hwndFrame, CommonGetLocalizedHelpFile
  751.                     ( PLAYER_ROOT_NAME, szHelp, PlayerQueryResources() ),
  752.                                                      HELP_QUIT, NULL );
  753.       return;
  754.      }
  755.  
  756.  
  757. // Function: AboutDlgProc - About dialog proc
  758. // --------------------------------------------------------------------
  759. // Parameters: As required by Microsoft Windows
  760. //
  761. // Returns:    As required by Microsoft Windows
  762. // --------------------------------------------------------------------
  763.    BOOL __export CALLBACK AboutDlgProc
  764.                      ( HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam )
  765.  
  766.      {BITMAP       bm;               // Temp bitmap struct
  767.       HWND         hwndCntrl;        // Handle of rect control that is painted
  768.       HDC          hdestDC;          // hdc of control rect
  769.       HDC          hmemDC;           // Memory dc
  770.       RECT         rcdestRect;       // Rect of control
  771.       HBITMAP      hbitmapSave;      // Prev bitmap
  772.       PAINTSTRUCT  ps;               // Paint struct
  773.  
  774.       switch( msg )
  775.         {case WM_COMMAND:
  776.              EndDialog( hdlg, 0 );
  777.              return TRUE;
  778.  
  779.          case WM_PAINT:
  780.    // Don't bother with error messages since only effect is that
  781.    // bitmap will not appear in dialog
  782.              if( !BeginPaint( hdlg, &ps ))
  783.                  return FALSE;
  784.              EndPaint( hdlg, &ps );
  785.  
  786.              if( !g.hAboutBitmap ||
  787.                  !( hwndCntrl = GetDlgItem( hdlg, PLAYER_ABOUT_BMPFRAME )))
  788.                  return FALSE;
  789.  
  790.              InvalidateRect( hwndCntrl, NULL, TRUE );
  791.              UpdateWindow( hwndCntrl );
  792.  
  793.              if( !(hdestDC = GetDC( hwndCntrl )))
  794.                  return FALSE;
  795.  
  796.              if( hmemDC = CreateCompatibleDC( hdestDC ))
  797.                 {if( hbitmapSave = SelectObject( hmemDC, g.hAboutBitmap ))
  798.                     {GetObject( g.hAboutBitmap, sizeof( BITMAP ), &bm );
  799.                      GetClientRect( hwndCntrl, &rcdestRect );
  800.  
  801.                      BitBlt( hdestDC,
  802.                          ( rcdestRect.right - bm.bmWidth ) / 2,
  803.                          ( rcdestRect.bottom - bm.bmHeight ) / 2,
  804.                          bm.bmWidth, bm.bmHeight, hmemDC, 0, 0, SRCCOPY );
  805.  
  806.                      SelectObject( hmemDC, hbitmapSave );
  807.                     }
  808.  
  809.                  DeleteDC( hmemDC );
  810.                 } 
  811.  
  812.              ReleaseDC( hwndCntrl, hdestDC );
  813.  
  814.              return FALSE;
  815.  
  816.          default:
  817.              return FALSE;
  818.         }
  819.  
  820.       return FALSE;
  821.      }
  822.  
  823.  
  824. // Function: PrintAbortProc - Print abort proc
  825. // --------------------------------------------------------------------
  826. // Parameters: As required by Microsoft Windows
  827. //
  828. // Returns:    As required by Microsoft Windows
  829. // --------------------------------------------------------------------
  830.    int __export CALLBACK PrintAbortProc( HDC hdc, int nCode )
  831.  
  832.      {MSG     msg;       // Message struct
  833.  
  834.       while( !g.bUserAbortPrint &&
  835.                  PeekMessage( &msg, NULL, NULL, NULL, PM_REMOVE ))
  836.          {
  837.           if( !g.hwndCancelPrt ||
  838.                              !IsDialogMessage( g.hwndCancelPrt, &msg ))
  839.              {TranslateMessage( &msg );
  840.               DispatchMessage( &msg );
  841.              }
  842.          }
  843.  
  844.       return !g.bUserAbortPrint;
  845.      }
  846.  
  847. // Function: PrintCancelDlgProc - User cancel printing dlg proc
  848. // --------------------------------------------------------------------
  849. // Parameters: As required by Microsoft Windows
  850. //
  851. // Returns:    As required by Microsoft Windows
  852. // --------------------------------------------------------------------
  853.    BOOL __export CALLBACK PrintCancelDlgProc
  854.                      ( HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam )
  855.  
  856.      {char    szName[MAX_NAME_LEN + 1];    // Buffer for movie name
  857.  
  858.       switch( msg )
  859.          {case WM_INITDIALOG:
  860.              SetFocus( GetDlgItem( hdlg, IDCANCEL ));
  861.              SetDlgItemText( hdlg, PRINT_CANCEL_MOVIENAME,
  862.                                  PlayerQueryActiveMovieName( szName ));
  863.              return TRUE;
  864.  
  865.           case WM_COMMAND:
  866.              return ( g.bUserAbortPrint = TRUE );
  867.  
  868.           case WM_DESTROY:
  869.              g.hwndCancelPrt = NULL;
  870.              break;
  871.          }
  872.  
  873.       return FALSE;
  874.      }
  875.  
  876. // Function: PrintDlgHookProc - Custom print common dlg hook function
  877. // --------------------------------------------------------------------
  878. // Parameters: As required by Microsoft Windows
  879. //
  880. // Returns:    As required by Microsoft Windows
  881. // --------------------------------------------------------------------
  882.    UINT __export CALLBACK PrintDlgHookProc
  883.                    (HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam )
  884.  
  885.      {    // The dialog ids are defined in dlgs.h
  886.           // Array of ids of controls to be hidden
  887.       static int nIDs[] = {grp1, rad1, rad2, rad3, stc2, edt1, 
  888.                            stc3, edt2, chx1, chx2, pshHelp };
  889.       UINT   i;            // Temp counter
  890.      
  891.  
  892.       if( message == WM_INITDIALOG )
  893.          {for( i=0; i < ( sizeof( nIDs ) / sizeof( nIDs[0] )); i++ )
  894.               ShowWindow( GetDlgItem( hdlg, nIDs[i] ), SW_HIDE );
  895.  
  896.           return TRUE;
  897.          }
  898.       else
  899.           return FALSE;
  900.      }
  901.  
  902.  
  903. // Function: PlayerEnableMenus - Disables menu items when there
  904. //                               are no movies
  905. // --------------------------------------------------------------------
  906. // Parameters: HWND       hwndFrame      Handle of frame window
  907. //             BOOL       bEnable        Enabling flag
  908. //
  909. // Returns:    VOID
  910. // --------------------------------------------------------------------
  911.    static VOID NEAR PlayerEnableMenus( HWND hwndFrame, BOOL bEnable )
  912.  
  913.      {UINT    fFlag;             // Temp enabling flag
  914.       HMENU   hmenuFrame;        // Handle to main menu of frame window
  915.       UINT    i;                 // Index
  916.  
  917.       static UINT uMenuIDs[] = {PLAYER_FILE_CLOSE,
  918.                                 PLAYER_FILE_PRINT,
  919.  
  920.                                 PLAYER_EDIT_COPY,
  921.                                 PLAYER_EDIT_OPTIONS,
  922.                                 PLAYER_EDIT_CANCELSEL,
  923.  
  924.                                 PLAYER_MOVIE_GETINFO,
  925.                                 PLAYER_MOVIE_STOPATEND,
  926.                                 PLAYER_MOVIE_LOOP,
  927.                                 PLAYER_MOVIE_BACKANDFORTH,
  928.                                 PLAYER_MOVIE_PLAYSELONLY,
  929.                                 PLAYER_MOVIE_HALFSIZE,
  930.                                 PLAYER_MOVIE_NORMALSIZE,
  931.                                 PLAYER_MOVIE_DOUBLESIZE,
  932.                                 PLAYER_MOVIE_SHOWPOSTER,
  933.  
  934.                                 PLAYER_WINDOW_TILE,
  935.                                 PLAYER_WINDOW_CASCADE,
  936.                                 PLAYER_WINDOW_ARRANGE
  937.                                };
  938.                                 
  939.  
  940.       if( !( hmenuFrame = GetMenu( hwndFrame )))
  941.           return;
  942.  
  943.       fFlag = (bEnable ? MF_ENABLED : MF_GRAYED ) | MF_BYCOMMAND;
  944.       for( i=0; i < sizeof( uMenuIDs ) / sizeof( uMenuIDs[0] ); i++ )
  945.           EnableMenuItem( hmenuFrame, uMenuIDs[i], fFlag );
  946.  
  947.       DrawMenuBar( hwndFrame );
  948.  
  949.       return;
  950.      }
  951.  
  952. // Function: TellUserCommonDlgError - Tell the user about the common dlg
  953. //                                    error
  954. // --------------------------------------------------------------------
  955. // Parameters: DWORD       dwError      error code returned by common dlg
  956. //
  957. // Returns:    VOID
  958. // --------------------------------------------------------------------
  959.    static VOID NEAR TellUserCommonDlgError( DWORD dwError )
  960.  
  961.      {WORD          wIDErrorString;   // String id
  962.  
  963.    // Not much here now, can make this as explicit as desired
  964.    // Now returns text of error id, i.e. "CDERR_INITIALIZATION"
  965.    // Not all messages are explicitly included
  966.  
  967.       switch( dwError )
  968.          {case CDERR_FINDRESFAILURE: 
  969.               wIDErrorString = PLAYER_STRING_CDLG_FINDRESFAIL;
  970.               break;
  971.           case CDERR_INITIALIZATION:
  972.               wIDErrorString = PLAYER_STRING_CDLG_INITFAIL;
  973.               break;
  974.           case CDERR_LOADRESFAILURE:
  975.               wIDErrorString = PLAYER_STRING_CDLG_LOADRESFAIL;
  976.               break;           
  977.           case CDERR_LOCKRESFAILURE:
  978.               wIDErrorString = PLAYER_STRING_CDLG_LOCKRESFAIL;
  979.               break;
  980.           case CDERR_MEMALLOCFAILURE:
  981.               wIDErrorString = PLAYER_STRING_CDLG_MEMALLOCFAIL;
  982.               break;
  983.           case CDERR_MEMLOCKFAILURE:
  984.               wIDErrorString = PLAYER_STRING_CDLG_MEMLOCKFAIL;
  985.               break;
  986.           case CDERR_STRUCTSIZE:
  987.               wIDErrorString = PLAYER_STRING_CDLG_STRUCTSIZE;
  988.               break;
  989.           case FNERR_INVALIDFILENAME:
  990.               wIDErrorString = PLAYER_STRING_CDLG_BADFILENAME;
  991.               break;
  992.           case PDERR_INITFAILURE:
  993.               wIDErrorString = PLAYER_STRING_CDLG_PRTINITFAIL;
  994.               break;
  995.           case PDERR_LOADDRVFAILURE:
  996.               wIDErrorString = PLAYER_STRING_CDLG_LOADDRVFAIL;
  997.               break;
  998.           case PDERR_NODEFAULTPRN:
  999.               wIDErrorString = PLAYER_STRING_CDLG_NODEFPRINTER;
  1000.               break;
  1001.           case PDERR_NODEVICES:
  1002.               wIDErrorString = PLAYER_STRING_CDLG_NODEVICES;
  1003.               break;
  1004.           case PDERR_PRINTERNOTFOUND:
  1005.               wIDErrorString = PLAYER_STRING_CDLG_NOFINDPNTR;
  1006.               break;
  1007.           case PDERR_SETUPFAILURE:
  1008.               wIDErrorString = PLAYER_STRING_CDLG_SETUPFAIL;
  1009.               break;
  1010.           default:
  1011.               wIDErrorString = PLAYER_STRING_CDLG_GENFAILURE;
  1012.               break;
  1013.          }
  1014.  
  1015.       if( wIDErrorString == PLAYER_STRING_CDLG_GENFAILURE )
  1016.           CommonTellUser( PlayerQueryResources(),
  1017.                          PLAYER_STRING_CDLG_GENFAILURE,
  1018.                                PLAYER_STRING_CDLG_CAP, MB_OK, dwError );
  1019.       else
  1020.           CommonTellUser( PlayerQueryResources(),
  1021.                      PLAYER_STRING_CDLG_FORMAT, PLAYER_STRING_CDLG_CAP,
  1022.                                                   MB_OK, wIDErrorString );
  1023.       return;
  1024.  
  1025.      }
  1026.  
  1027.  
  1028. //  The remaining functions are the query functions called by other modules
  1029.  
  1030. // Function: PlayerQueryClientWindow - Query Client Window Handle
  1031. // --------------------------------------------------------------------
  1032. // Parameters: None.
  1033. //
  1034. // Returns:    HWND g.hwndClient;        MDI client window handle
  1035. // --------------------------------------------------------------------
  1036.    HWND FAR PlayerQueryClientWindow( VOID )
  1037.  
  1038.      {return g.hwndClient;
  1039.      }
  1040.  
  1041. // Function: PlayerQueryNumMovies - Query number of movies
  1042. // --------------------------------------------------------------------
  1043. // Parameters: None.
  1044. //
  1045. // Returns:    HWND g.wNumMovies;        Number of movies
  1046. // --------------------------------------------------------------------
  1047.    WORD FAR PlayerQueryNumMovies( VOID )
  1048.  
  1049.      {return g.wNumMovies;
  1050.      }
  1051.  
  1052. // Function: PlayerQueryMDIAction - Query tile, cascade or icon arrange.
  1053. // --------------------------------------------------------------------
  1054. // Parameters: None.
  1055. //
  1056. // Returns:    WORD   wTileCascadeArrange    MDI action menu id
  1057. // --------------------------------------------------------------------
  1058.    WORD FAR PlayerQueryMDIAction( VOID )
  1059.  
  1060.      {return g.wTileCascadeArrange;
  1061.      }
  1062.  
  1063.